package gui.Student;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;

import System.MainControl;
/**Student Main Panel*/
public class StudentMainPanel extends JPanel implements ActionListener 
{
	/**
	 * 
	 */
	private static final long serialVersionUID = -5214559008309338361L;
	/**panel variables*/
	private JTextField txtWelcome;
	private JButton btnCommitExam;
	private JButton btnManualExam;
	private JButton btnGradesReview;
	private JButton btnExit;

	/**
	 * Create the panel.
	 */
	public StudentMainPanel() {
		setBorder(new TitledBorder(null, "Student Main Menu", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		setBackground(SystemColor.activeCaption);
		setBounds(100, 100, 622, 284);
		setLayout(null);
		
		add(getBtnCommitExam());
		add(gettextWelcome());
		add(getBtnManualExam());
		add(getBtnGradesReview());
		add(getbtnExit());
	}
	
	private JTextField gettextWelcome()
	{
		if (txtWelcome == null)
		{
			DateFormat dateFormat = new SimpleDateFormat("EEE, MMM d, ''yy",Locale.US);
			Date date = new Date();
			txtWelcome = new JTextField();
			txtWelcome.setEditable(false);
			txtWelcome.setFont(new Font("Tahoma", Font.BOLD, 12));
			txtWelcome.setText("| Welcome "+ MainControl.currentUser.getFirstName() + " | -- | Date: " + dateFormat.format(date) + " |");
			txtWelcome.setBackground(new Color(100, 149, 237));
			txtWelcome.setBounds(98, 23, 330, 28);
		}
		return txtWelcome;
	}
	
	private JButton getBtnCommitExam()
	{
		if(btnCommitExam == null)
		{
			btnCommitExam = new JButton("<html>Commit Exam</html>");
			btnCommitExam.setForeground(SystemColor.desktop);
			btnCommitExam.setIcon(MainControl.IconAssReview);
			btnCommitExam.setFont(MainControl.MainPanelFont);
			btnCommitExam.setBounds(62, 75, 141, 40);
			btnCommitExam.addActionListener(this);
		}
		return btnCommitExam;
	}
	
	private JButton getBtnManualExam()
	{
		if(btnManualExam == null)
		{
			btnManualExam = new JButton("<html>Upload Maual Exam</html>");
			btnManualExam.setForeground(SystemColor.desktop);
			//btnManualExam.setIcon(MainControl.IconAssSubmission);
			btnManualExam.setFont(MainControl.MainPanelFont);
			btnManualExam.setBounds(62, 129, 141, 40);
			btnManualExam.addActionListener(this);
		}
		return btnManualExam;
	}
	
	private JButton getBtnGradesReview()
	{
		if(btnGradesReview == null)
		{
			btnGradesReview= new JButton("<html>Grades Review</html>");
			btnGradesReview.setForeground(SystemColor.desktop);
			//btnGradesReview.setIcon(MainControl.IconStudentFile);
			btnGradesReview.setFont(MainControl.MainPanelFont);
			btnGradesReview.setBounds(62, 184, 141, 40);
			btnGradesReview.addActionListener(this);
		}
		return btnGradesReview;
	}
	
	private JButton getbtnExit()
	{
		if (btnExit == null)
		{
			btnExit = new JButton("LogOut");
			btnExit.setSize(new Dimension(81, 40));
			btnExit.setLocation(455, 184);
			btnExit.setFont(MainControl.guiFont);
			btnExit.setBorder(BorderFactory.createLineBorder(SystemColor.desktop));
			btnExit.addActionListener(this);
		}
		return btnExit;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		if(e.getSource() == btnCommitExam)
		{
			MainControl.setStudentWindows(1);
		}
			
	/*	if(e.getSource() == btnManualExam)
		{
			MainControl.setStudentWindows(2);
		}
	*/
		if(e.getSource() == btnGradesReview)
		{
			MainControl.setStudentWindows(2);
		}
		if (e.getSource() == btnExit)
		{
			MainControl.LogOut(this);
		}
	}
}
